<template>
  <div class="layout-container antijam-test-sample-data">
    <FlowStep :activeStep="1" />
    <div class="search common-buttons">
      <el-input
        v-model="keyword"
        style="width: 320px"
        placeholder="请搜索"
        clearable
      ></el-input>
      <el-button type="primary" :icon="Search" @click="onQuery({ pageNo: 1 })"
        >查找</el-button
      >
    </div>

    <div class="layout-container-table">
      <CommonTable
        :data="state.tableData"
        v-model:page="page"
        highlight-current-row
        :total="total"
        v-loading="loading"
        :show-selection="false"
        @onQuery="onQuery"
        @current-change="handleCurrentChange"
      >
        <el-table-column prop="sampleName" label="试验样本名称" />
        <el-table-column prop="dytStyle" label="导引头体制" />
        <el-table-column prop="interType" label="干扰类型" />
        <el-table-column prop="interScenType" label="干扰场景类型" />
        <el-table-column prop="foreignElectEquip" label="外军电子战装备类型" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column prop="evaluationStage" label="推算状态">
          <!-- evaluationStage=3未推算，4和5是已推算 -->
          <template #default="scope">
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '3'"
            >
              <div class="round" style="background: #3868fe"></div>
              <span style="color:#3868fe">未推算</span>
            </div>
            <div
              class="evaluation-process"
              v-else
            >
              <div class="round" style="background: rgba(22, 168, 49, 1)"></div>
              <span style="color:rgba(22, 168, 49, 1)">已推算</span>
            </div>
          </template>
        </el-table-column>
      </CommonTable>
    </div>
    <div class="step-buttons common-buttons">
      <el-button type="primary" @click="onStep">下一步</el-button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref } from 'vue';
import { ElMessage, FormInstance, ElMessageBox } from 'element-plus';
import { useRoute, useRouter } from 'vue-router';
import { Search } from '@element-plus/icons-vue';
import CommonTable from '@/components/common-table/index.vue';
import { Page } from '@/components/common-table/type';
import { httpConfidenceEvaluateList } from '@/api/antiJamPerformCalculateSystem';
import FlowStep from '../FlowStep/index.vue'

let $router = useRouter();
const keyword = ref<string>('');
const state = reactive<any>({
  tableData: [],
});
const currentRow = ref();
//const selectKeys = ref<string[]>([]);
const loading = ref<boolean>(false);
const formRef = ref<FormInstance>();
const page = reactive<Page>({
  current: 1,
  pageSize: 20,
});
const total = ref<number>(0);
const record = ref<Object>({});

onMounted(() => {
  onQuery({ pageNo: 1 });
});

// 查询数据
const onQuery = (val: any) => {
  const params = {
    sampleName: keyword.value,
    sampleType: '1', // 0-原始样本，1-处理后样本
    sampleId: '',
    evaluationStage: '3',
    pageSize: page.pageSize,
    pageNo: page.current,
    ...val,
  };
  loading.value = true;
  httpConfidenceEvaluateList(params).then((res) => {
    const result = res.data;
    loading.value = false;
    const { rows, totalRows } = result;
    total.value = totalRows;
    state.tableData = rows;
    currentRow.value = null;
  });
};

// 选择监听器
const handleCurrentChange = (val: any) => {
  currentRow.value = val;
};

// 下一步
const onStep = () => {
  if ( !currentRow.value ) {
    ElMessage({
      message: '请选择试验数据',
      type: 'warning',
    });
    return;
  }
  $router.push({
    path: '/antiJamPerformCalculateSystem/fuseCalculate',
    query: {
      sampleId: currentRow.value.id,
      sampleName: currentRow.value.sampleName,
    },
  });
};
</script>

<style lang="scss" scoped>
@import '@/assets/style/buttons';
.antijam-test-sample-data {
  .search {
    display: flex;
    padding: 16px;
    :deep() {
      .el-input--small .el-input__wrapper {
        margin-right: 10px;
      }
    }
  }
  .layout-container-table {
    .el-button--small {
      background: transparent;
      color: rgba(24, 81, 237, 1);
    }
  }

  .evaluation-process {
    display: flex;
    cursor: pointer;
    // color: rgb(24, 81, 237);
    .round {
      display: inline-block;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      position: relative;
      top: 7px;
      right: 4px;
    }
  }

  .step-buttons {
    display: flex;
    justify-content: center;
    box-shadow: 0px 0px 10px rgba(218, 222, 224, 1);
    padding: 10px 0;
  }
}
.el-button {
    background: rgb(1, 18, 90);
    border: 0;
  }
</style>
